/**   
 * @Title: LoginManagerImpl.java
 * @Package com.stusys.service.commons.impl
 * @Description: TODO
 * @author xhn 
 * @date 2012-11-12 下午09:26:01
 * @version V1.0   
 */
package com.parttime.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;



















import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.parttime.actions.LoginVO;
import com.parttime.dao.MerchantUsersDao;
import com.parttime.dao.PersonalUsersDao;
import com.parttime.service.LoginManager;


/**
 * @ClassName: LoginManagerImpl
 * @Description: 登录逻辑处理
 * @author mcx
 * 
 */
@Service
public class LoginManagerImpl implements LoginManager {

	@Autowired
	private PersonalUsersDao personalUsersDao;
	@Autowired
	private MerchantUsersDao merchantUsersDao;
	@Override
	public Map<String, Object> login(LoginVO user) throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		String user_type=user.getUser_type();
		if(user.getLoginname()==null||user.getLoginname().equals("")){
			map.put("msg", "账号不能为空");return map;
			
		}else if(user.getLoginpassword()==null||user.getLoginpassword().equals("")){
			map.put("msg", "密码不能为空");return map;
		}
		else if(user_type.equals("personal")){
			if(!personalUsersDao.exitsUserByAccount(user.getLoginname())){
				map.put("msg", "账号不存在");return map;
			}else if(!personalUsersDao.authPasswordByAccount(user.getLoginpassword(), user.getLoginname())){
				map.put("msg", "密码错误");return map;
				
			}
			else map.put("User", user);
		}else if(user_type.equals("merchant")){
			if(!merchantUsersDao.exitsUserByAccount(user.getLoginname())){
				map.put("msg", "账号不存在"); return map;
			}else if (!merchantUsersDao.authPasswordByAccount(user.getLoginname(),user.getLoginpassword())){
				map.put("msg", "密码错误");return map;
			}
			map.put("User", user);
			return map;
		}
		else {
			map.put("msg", "出错");return map;
		}
		return map;
	}


}
